﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TaxBiz.SysConfig;
using BaseData.UI;
using TaxEntity.SysConfig;

namespace Admin.AjaxPage
{
    public partial class DiduanConfig : BaseCommon.BasePage
    {
        private const string SelectDataTemplate = "<option value='{0}'>{1}</option>";

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!HasPower())
            //{
            //    Jscript.AlertAndGoBack("您权限不足，不能操作");
            //    return;
            //}
            string retMessage = string.Empty;
            string action = PageContext.GetRequest("action");

            switch (action.ToLower())
            {
                case "getjiedaolist":
                    string strxiangzhenID = PageContext.GetRequest("xianzhenID");
                    int xiangzhenID = 0;
                    int.TryParse(strxiangzhenID, out xiangzhenID);
                    if (xiangzhenID > 0)
                    {
                        retMessage = this.GetJiedaoList(xiangzhenID);
                    }
                    break;
                case "getdiduanlist": 
                    string strjiedaoID = PageContext.GetRequest("jiedaoID");
                    int jiedaoID = 0;
                    int.TryParse(strjiedaoID, out jiedaoID);
                    if (jiedaoID > 0)
                    {
                        retMessage = this.GetDiduanList(jiedaoID);
                    }
                    break;
            }
            Response.ContentType = "text/plain";
            Response.Write(retMessage);
        }

        //获取街道信息
        protected string GetJiedaoList(int xiangzhenID)
        {
            string retInfo = string.Empty;
            JiedaoBiz ub = new JiedaoBiz();
            DataTable dt = ub.GetList(xiangzhenID);
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string showName = dr["Name"].ToString();
                    retInfo += string.Format(SelectDataTemplate, dr["id"], showName);
                }
            }
            return retInfo;
        }
        //获取地段信息
        protected string GetDiduanList(int jiedaoID)
        {
            string retInfo = string.Empty;
            DiDuanBiz ub = new DiDuanBiz();
            DataTable dt = ub.GetList(jiedaoID);
            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string showName = dr["Name"].ToString();
                    retInfo += string.Format(SelectDataTemplate, dr["id"], showName);
                }
            }
            return retInfo;
        }
    }
}